package com.janko.springbootbase.proxy;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * 手动写一个切面类，实现记录日志和计算方法执行时间
 */
@Aspect
@Component
public class AspectConfig {

    @Pointcut("execution(* com.janko.springbootbase.service.*.*(..)))")
    private void pointcut(){

    }

    @Around("pointcut()")
    public Object Around(ProceedingJoinPoint point) throws  Throwable{
        long start=System.currentTimeMillis();
        Object result=point.proceed();
        long end=System.currentTimeMillis();
        System.out.println("该方法的执行时间是："+(end-start)+"ms");
        return result;
    }
}
